#!/bin/bash
############################
# creating release file
# (c) yudi rosandi
#

PREF=$(awk '{r=$1}END{print r}' RELEASED)
MAJOR=$(echo $PREF|cut -d. -f1)
MINOR=$(echo $PREF|cut -d. -f2)
REVIS=$(echo $PREF|cut -d. -f3)

# default is increase revision number
[[ -z $1 ]] && REVIS=$[ ${REVIS} + 1 ]
[[ $1 = rev ]] && REVIS=$[ ${REVIS} + 1 ]
[[ $1 = min ]] && MINOR=$[ ${MINOR} + 1 ]
[[ $1 = maj ]] && MAJOR=$[ ${MAJOR} + 1 ]

# make tgz source release
RELNAME=xlider-${MAJOR}.${MINOR}.${REVIS}
echo releasing ${RELNAME}
echo ${MAJOR}.${MINOR}.${REVIS} $(date +"%d.%m.%Y") >> RELEASED
svn export . /tmp/${RELNAME}
cd /tmp
tar cz ${RELNAME} > ${RELNAME}.tgz
cd $OLDPWD
mv /tmp/${RELNAME}.tgz .
rm -rf /tmp/${RELNAME}

# make binary deb file

(echo $@ | grep makedeb) || exit 0

TARDIR=/tmp/${RELNAME}/usr/local

make clean all
strip -s src/xlider
./install /tmp/${RELNAME}/usr onlycopy
cp -a deb /tmp/${RELNAME}/DEBIAN
awk '/^Version:/{print "Version: "'${MAJOR}'.'${MINOR}'.'${REVIS}';next}{print}' deb/control > /tmp/${RELNAME}/DEBIAN/control
fakeroot dpkg-deb --build /tmp/${RELNAME}
mv /tmp/${RELNAME}.deb .
rm -rf /tmp/${RELNAME}
